﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FIFP.Common;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls.Charting;
using System.Collections.Generic;
using Telerik.Windows.Controls;
using EffectiveCapacityReport;
using FIFP.DashBoard.Helper;

namespace FIFP.DashBoard.ViewModel
{
    public class ChartViewModel : ViewModelCore
    {
        #region Variables
        myDialog dialog;
        RadChart chart;
        #endregion

        #region Properties
        ObservableCollection<List<DataPoint>> _DivisionLossList = new ObservableCollection<List<DataPoint>>();
        public ObservableCollection<List<DataPoint>> DivisionLossList
        {
            get { return _DivisionLossList; }
            set { SetPropertyValue(() => DivisionLossList, value, val => _DivisionLossList = val); }
        }

        List<DataPoint> _EffectiveCapacityList = new List<DataPoint>();
        public List<DataPoint> EffectiveCapacityList
        {
            get { return _EffectiveCapacityList; }
            set { SetPropertyValue(() => EffectiveCapacityList, value, val => _EffectiveCapacityList = val); }
        }

        List<DataPoint> _ReservoirCapacityList = new List<DataPoint>();
        public List<DataPoint> ReservoirCapacityList
        {
            get { return _ReservoirCapacityList; }
            set { SetPropertyValue(() => ReservoirCapacityList, value, val => _ReservoirCapacityList = val); }
        }

        ObservableCollection<List<DataPoint>> _MonthlyLossList = new ObservableCollection<List<DataPoint>>();
        public ObservableCollection<List<DataPoint>> MonthlyLossList
        {
            get { return _MonthlyLossList; }
            set { SetPropertyValue(() => MonthlyLossList, value, val => _MonthlyLossList = val); }
        }

        #endregion

        #region Commands
        private ICommand _RadChartMouseLeftButtonCommand;
        public ICommand RadChartMouseLeftButtonCommand
        {
            get
            {
                return _RadChartMouseLeftButtonCommand ??
                        (_RadChartMouseLeftButtonCommand = new RelayCommand<RadChart>(ZoomInChartWithLabels));
            }
        }
        #endregion

        #region Constructor
        public ChartViewModel()
        {
            LoadDivisionLossData();
            LoadEffectiveCapacityData();
            LoadReservoirCapacityData();
            LoadMonthlyLossData();
        }
        #endregion

        #region Methods
        private void LoadDivisionLossData()
        {
            DivisionLossList = new ObservableCollection<List<DataPoint>>() 
            {
                new List<DataPoint>(){new DataPoint(){ Low = 0, High=326, Label="326", XCategory="Res.Cap" }},
                new List<DataPoint>(){new DataPoint(){ Low = 312, High=326, Label="14", XCategory="Drilling" }},
                new List<DataPoint>(){new DataPoint(){ Low = 294, High=312, Label="18", XCategory="Projects" }},
                new List<DataPoint>(){new DataPoint(){ Low = 286, High=294, Label="8", XCategory="Maint." }},
                new List<DataPoint>(){new DataPoint(){ Low = 279, High=286, Label="7", XCategory="Integrity"} },
                new List<DataPoint>(){new DataPoint(){ Low = 276, High=279, Label="3", XCategory="Monitoring"} },
                new List<DataPoint>(){new DataPoint(){ Low = 275, High=276, Label="1", XCategory="Unplanned" }},
                new List<DataPoint>(){new DataPoint(){ Low = 0, High=275, Label="275", XCategory="Eff.Cap" }}
            };
        }

        private void LoadEffectiveCapacityData()
        {
            EffectiveCapacityList = new List<DataPoint>() 
            {
                new DataPoint(){ YValue=284, XCategory="Jan"},
                new DataPoint(){ YValue=302, XCategory="Feb"},
                new DataPoint(){ YValue=299, XCategory="Mar"},
                new DataPoint(){ YValue=277, XCategory="Apr"},
                new DataPoint(){ YValue=275 ,XCategory="May"},
                new DataPoint(){ YValue=275, XCategory="Jun"},
                new DataPoint(){ YValue=270, XCategory="Jul"},
                new DataPoint(){ YValue=260 ,XCategory="Aug"},
                new DataPoint(){ YValue=265 ,XCategory="Sep"},
                new DataPoint(){ YValue=260, XCategory="Oct"},
                new DataPoint(){ YValue=260, XCategory="Nov"},
                new DataPoint(){ YValue=260, XCategory="Dec"}};
        }

        private void LoadReservoirCapacityData()
        {
            ReservoirCapacityList = new List<DataPoint>() 
            {
                new DataPoint(){ YValue=328, XCategory="Jan"},
                new DataPoint(){ YValue=302, XCategory="Feb"},
                new DataPoint(){ YValue=304, XCategory="Mar"},
                new DataPoint(){ YValue=300, XCategory="Apr"},
                new DataPoint(){ YValue=330 ,XCategory="May"},
                new DataPoint(){ YValue=335, XCategory="Jun"},
                new DataPoint(){ YValue=325, XCategory="Jul"},
                new DataPoint(){ YValue=313 ,XCategory="Aug"},
                new DataPoint(){ YValue=332 ,XCategory="Sep"},
                new DataPoint(){ YValue=350, XCategory="Oct"},
                new DataPoint(){ YValue=354, XCategory="Nov"},
                new DataPoint(){ YValue=340, XCategory="Dec"}};
        }

        private void LoadMonthlyLossData()
        {
            MonthlyLossList.Add(ReservoirCapacityList);
            MonthlyLossList.Add(EffectiveCapacityList);

            List<DataPoint> monitorList = new List<DataPoint>() 
            {
                new DataPoint(){ YValue=5, XCategory="Jan"},
                new DataPoint(){ YValue=9, XCategory="Feb"},
                new DataPoint(){ YValue=8, XCategory="Mar"},
                new DataPoint(){ YValue=4, XCategory="Apr"},
                new DataPoint(){ YValue=13,XCategory="May"},
                new DataPoint(){ YValue=4, XCategory="Jun"},
                new DataPoint(){ YValue=2, XCategory="Jul"},
                new DataPoint(){ YValue=7 ,XCategory="Aug"},
                new DataPoint(){ YValue=3 ,XCategory="Sep"},
                new DataPoint(){ YValue=6, XCategory="Oct"},
                new DataPoint(){ YValue=4, XCategory="Nov"},
                new DataPoint(){ YValue=4, XCategory="Dec"}};

            MonthlyLossList.Add(monitorList);

            List<DataPoint> unPlannedList = new List<DataPoint>() 
            {
                new DataPoint(){ YValue=12, XCategory="Jan"},
                new DataPoint(){ YValue=11, XCategory="Feb"},
                new DataPoint(){ YValue=21, XCategory="Mar"},
                new DataPoint(){ YValue=9, XCategory="Apr"},
                new DataPoint(){ YValue=21,XCategory="May"},
                new DataPoint(){ YValue=9, XCategory="Jun"},
                new DataPoint(){ YValue=15, XCategory="Jul"},
                new DataPoint(){ YValue=23 ,XCategory="Aug"},
                new DataPoint(){ YValue=10 ,XCategory="Sep"},
                new DataPoint(){ YValue=15, XCategory="Oct"},
                new DataPoint(){ YValue=18, XCategory="Nov"},
                new DataPoint(){ YValue=11, XCategory="Dec"}};

            MonthlyLossList.Add(unPlannedList);

            List<DataPoint> drillingList = new List<DataPoint>() 
            {
                new DataPoint(){ YValue=23, XCategory="Jan"},
                new DataPoint(){ YValue=10, XCategory="Feb"},
                new DataPoint(){ YValue=10, XCategory="Mar"},
                new DataPoint(){ YValue=13, XCategory="Apr"},
                new DataPoint(){ YValue=14, XCategory="May"},
                new DataPoint(){ YValue=14, XCategory="Jun"},
                new DataPoint(){ YValue=10, XCategory="Jul"},
                new DataPoint(){ YValue=14 ,XCategory="Aug"},
                new DataPoint(){ YValue=14 ,XCategory="Sep"},
                new DataPoint(){ YValue=13, XCategory="Oct"},
                new DataPoint(){ YValue=15, XCategory="Nov"},
                new DataPoint(){ YValue=18, XCategory="Dec"}};

            MonthlyLossList.Add(drillingList);

            List<DataPoint> projectList = new List<DataPoint>() 
            {
                new DataPoint(){ YValue=6, XCategory="Jan"},
                new DataPoint(){ YValue=6, XCategory="Feb"},
                new DataPoint(){ YValue=4, XCategory="Mar"},
                new DataPoint(){ YValue=8, XCategory="Apr"},
                new DataPoint(){ YValue=6, XCategory="May"},
                new DataPoint(){ YValue=8, XCategory="Jun"},
                new DataPoint(){ YValue=21, XCategory="Jul"},
                new DataPoint(){ YValue=26 ,XCategory="Aug"},
                new DataPoint(){ YValue=20 ,XCategory="Sep"},
                new DataPoint(){ YValue=44, XCategory="Oct"},
                new DataPoint(){ YValue=36, XCategory="Nov"},
                new DataPoint(){ YValue=36, XCategory="Dec"}};

            MonthlyLossList.Add(projectList);

            List<DataPoint> maintenanceList = new List<DataPoint>() 
            {
                new DataPoint(){ YValue=5,  XCategory="Jan"},
                new DataPoint(){ YValue=11, XCategory="Feb"},
                new DataPoint(){ YValue=12, XCategory="Mar"},
                new DataPoint(){ YValue=11, XCategory="Apr"},
                new DataPoint(){ YValue=12, XCategory="May"},
                new DataPoint(){ YValue=12, XCategory="Jun"},
                new DataPoint(){ YValue=17, XCategory="Jul"},
                new DataPoint(){ YValue=15 ,XCategory="Aug"},
                new DataPoint(){ YValue=14 ,XCategory="Sep"},
                new DataPoint(){ YValue=15, XCategory="Oct"},
                new DataPoint(){ YValue=19, XCategory="Nov"},
                new DataPoint(){ YValue=20, XCategory="Dec"}};

            MonthlyLossList.Add(maintenanceList);

            List<DataPoint> integrityList = new List<DataPoint>() 
            {
                new DataPoint(){ YValue=14,  XCategory="Jan"},
                new DataPoint(){ YValue=13, XCategory="Feb"},
                new DataPoint(){ YValue=15, XCategory="Mar"},
                new DataPoint(){ YValue=10, XCategory="Apr"},
                new DataPoint(){ YValue=19, XCategory="May"},
                new DataPoint(){ YValue=19, XCategory="Jun"},
                new DataPoint(){ YValue=14, XCategory="Jul"},
                new DataPoint(){ YValue=20 ,XCategory="Aug"},
                new DataPoint(){ YValue=13 ,XCategory="Sep"},
                new DataPoint(){ YValue=10, XCategory="Oct"},
                new DataPoint(){ YValue=0, XCategory="Nov"},
                new DataPoint(){ YValue=0, XCategory="Dec"}};

            MonthlyLossList.Add(integrityList);

            List<DataPoint> sumList = new List<DataPoint>() 
            {
                new DataPoint(){ YValue=79,  XCategory="Jan",Label="65"},
                new DataPoint(){ YValue=70, XCategory="Feb",Label="60"},
                new DataPoint(){ YValue=80, XCategory="Mar",Label="70"},
                new DataPoint(){ YValue=65, XCategory="Apr",Label="55"},
                new DataPoint(){ YValue=95, XCategory="May",Label="85"},
                new DataPoint(){ YValue=76, XCategory="Jun",Label="66"},
                new DataPoint(){ YValue=90, XCategory="Jul",Label="70"},
                new DataPoint(){ YValue=115, XCategory="Aug",Label="105"},
                new DataPoint(){ YValue=84 ,XCategory="Sep",Label="74"},
                new DataPoint(){ YValue=11, XCategory="Oct",Label="102"},
                new DataPoint(){ YValue=102, XCategory="Nov",Label="92"},
                new DataPoint(){ YValue=99, XCategory="Dec",Label="89"}};

            MonthlyLossList.Add(sumList);
        }

        private void ZoomInChartWithLabels(RadChart radChart)
        {
            foreach (SeriesMapping collection in ServiceLocator.Get<LossByMonth>().radChart.SeriesMappings)
                collection.SeriesDefinition.ShowItemLabels = true;

            if (dialog == null)
            {
                dialog = new myDialog(ServiceLocator.Get<LossByMonth>());
            }
            dialog.Show();
        }


        #endregion
    }
}